/**
 * Author: Lipovcev Bogdan (seclan@mail.ru)
 * Version: 0.0.1
 * Requires: haxe>=v2.05, swf-version>=10
 */
import flash.display.MovieClip;
import flash.Vector;
import flash.events.Event;
import flash.media.Sound;
import flash.media.SoundLoaderContext;
import flash.media.SoundChannel;
import flash.media.SoundMixer;
import flash.media.SoundTransform;
import flash.net.URLRequest;

import flash.display.Stage;

import MyImages;
import MiniGui;

class Bot extends MovieClip
{

    public function new() {
        super();
        addEventListener(Event.ENTER_FRAME, move);
        flash.Lib.current.stage.addEventListener(flash.events.KeyboardEvent.KEY_DOWN, myOnKeyDown, false );
        flash.Lib.current.stage.addEventListener(flash.events.MouseEvent.CLICK, myMouseClick, false);
        y = 100;
    }
    
    public function move(event:flash.events.MouseEvent):Void {
        //this.gotoAndStop(1);
        //this.gotoAndPlay(1);
    }
    
    public function myOnKeyDown(event:flash.events.KeyboardEvent) { 
    	if ( event.keyCode == 32) this.stop();
    	if ( event.keyCode == 18) this.play();
    	if ( event.keyCode == 39) this.x += 3;
    	if ( event.keyCode == 37) this.x -= 3;
	} 
	
	public function myMouseClick(event:flash.events.MouseEvent) {
		var xx:Float = event.localX;
		var yy:Float = event.localY;
		//trace(xx+' '+yy);
		x = event.localX;
		y = event.localY;
		if((xx > x) && (yy > y) && ((x+width) < xx) && ((y+height) < yy)) {
			//trace("123123");
			//x = event.localX;
			//y = event.localY;
		}
	}
}

class Button extends MovieClip {
	public function new() {
		super();
	}
}

class LoadSwfImage {
private var imgs:Vector<MovieClip>;
private var m_parent:MovieClip;
private var m_startPage:YahClickToPlay;

private var lbl : Label;

public function LoadAllImages(){
	imgs.push(flash.Lib.attach("Background"));	
	imgs.push(flash.Lib.attach("Back"));
	imgs.push(flash.Lib.attach("Background"));
}

public function ViewGame(){
	imgs[1].y = 100;
	imgs[2].x = 256;

	flash.Lib.current.addChild(imgs[0]);
	flash.Lib.current.addChild(imgs[2]);
	flash.Lib.current.addChild(imgs[1]);

	var qqq:Bot = new Bot();
	flash.Lib.current.addChild(qqq);
}

public function move(event:flash.events.MouseEvent):Void {
	lbl.SetText(event.localX+" "+event.localY);
	flash.Lib.current.addChild(lbl);
}

public function new() {
	lbl = new Label(0xFF0000, "Vernada", 12);
	flash.Lib.current.stage.addEventListener(flash.events.MouseEvent.MOUSE_MOVE, move, false);
	
	//imgs = new Vector();
	//LoadAllImages();
	//ViewGame();
	
	var v:MyButton = new MyButton(new MenuButton(),new MenuButton2(),new MenuButton3(),new MenuButton2(), 100, 100, 0x0000FF, "Vernada", 15, "Новая игра");
	var vv:MyButton = new MyButton(new MenuButton(),new MenuButton2(),new MenuButton3(),new MenuButton2(), 100, 200, 0x0000FF, "Vernada", 15, "Авторы");
	flash.Lib.current.addChild(v);
	flash.Lib.current.addChild(vv);
	
	var sound:Sound = new Sound();
	var req:URLRequest = new URLRequest("qwe.mp3");
	var context:SoundLoaderContext = new SoundLoaderContext(8000, true);
	sound.load(req,context);
	sound.play();
}

public static function main():Void {
	new LoadSwfImage();
}
}